package cn.kattomy.shop.category.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import cn.kattomy.shop.base.dao.BaseDao;
import cn.kattomy.shop.category.dao.CategoryDao;
import cn.kattomy.shop.category.vo.Category;
import cn.kattomy.shop.utils.PageBean;

public class CategoryDaoImpl extends BaseDao implements CategoryDao{
	
	@Override
	public List<Category> queryForAll() {
		String hql = "FROM Category order by cid";
		return getSession().createQuery(hql).list();
	}

	@Override
	public void save(Category category) {
		getSession().save(category);
	}
	
	@Override
	public void update(Category category) {
		getSession().update(category);
	}

	@Override
	public Category findByCid(Integer cid) {
		return (Category) getSession().get(Category.class, cid);
	}

	@Override
	public void delete(Category category) {
		getSession().delete(category);
	}

	@Override
	public int findCount() {
		String hql = "Select count(*) From Category ";
		List<Long> list = getSession().createQuery(hql).list();
		if (list != null && list.size() > 0) {
			return list.get(0).intValue();
		}
		return 0;
	}

	@Override
	public List<Category> findByPage(int begin, int pageSize) {
		String hql = "From Category Order By cid DESC";
		List<Category> list = getSession().createQuery(hql).setFirstResult(begin).setMaxResults(pageSize).list();
		if (list != null && list.size() > 0) {
			return list;
		}
		return null;
	}

	
}
